local RSNG = RSNG
local AceOO = AceLibrary("AceOO-2.0")
local BC = AceLibrary("Babble-Class-2.2")
local L = AceLibrary("Ace-Locale-2.2"):new("RSNG")
local C = RSNG.Classes

local CLASSES = {
	DRUID = true,
	HUNTER = true,
	MAGE = true,
	PALADIN = true,
	PRIEST = true,
	ROGUE = true,
	SHAMAN = true,
	WARLOCK = true,
	WARRIOR = true,
}

local Filter = AceOO.Class(C.IFilter)

function Filter.prototype:init()
	Filter.super.prototype.init(self)
	self.classes = {}
end

function Filter.prototype:Filter(unit, name, class, group, dead, online)
	return self.classes[class]
end

function Filter.prototype:Serialize(type, data)
	local c = self.classes
	if type == "save" then
		for i in pairs(CLASSES) do
			data[i] = c[i]
		end
	elseif type == "load" then
		for i in pairs(CLASSES) do
			c[i] = data[i]
		end
	end
end

function Filter.prototype:GetOptionTable()
	local t = self.options
	if not t then
		t = {}
		for c in pairs(CLASSES) do
			local rev = BC:ReverseTranslation(c)
			t[c] = {
				type = "toggle",
				name = rev,
				desc = L["Filter class %s."]:format(rev),
				get = function () return self.classes[c] end,
				set = function (value) self.classes[c] = value and true or false end,
			}
		end
		self.options = t
	end
	return t
end

RSNG:RegisterFilter(L["Class Filter"], Filter)
